package com.cq.digitalemployee.user.service.impl;

import com.cq.digitalemployee.user.dao.SysPermissionDao;
import com.cq.digitalemployee.user.entity.po.SysPermission;
import com.cq.digitalemployee.user.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    SysPermissionDao sysPermissionDao;

    @Override
    public Set<SysPermission> findAllPermissionByUser(String userId) {
        return sysPermissionDao.selectAllUserPermisson(userId);
    }

    @Override
    public List<SysPermission> findAll() {
        return sysPermissionDao.selectAll();
    }

    @Override
    public SysPermission findById(String id) {
        return sysPermissionDao.selectByPrimaryKey(id);
    }

    @Override
    public Set<SysPermission> findByUser(String userId) {
        return sysPermissionDao.selectByUser(userId);
    }

    @Override
    public Set<SysPermission> findByRole(String roleId) {
        return sysPermissionDao.selectByRole(roleId);
    }

    @Override
    public int add(SysPermission sysPermission) {
        return sysPermissionDao.insertSelective(sysPermission);
    }

    @Override
    public int edit(SysPermission sysPermission) {
        return sysPermissionDao.updateByPrimaryKeySelective(sysPermission);
    }

    @Override
    public int delete(String id) {
        return sysPermissionDao.deleteByPrimaryKey(id);
    }

    @Override
    public int grantByUser(String permissionId, String userId) {
        return sysPermissionDao.grantByUser(permissionId, userId);
    }

    @Override
    public int grantByRole(String permissionId, String roleId) {
        return sysPermissionDao.grantByRole(permissionId, roleId);
    }
}
